## Figure A6: Clustering of Closing Dates by Day of Week and Neighborhood Race

## install.packages(c("tidyverse"))
## library(tidyverse)

## SET WORKING DIRECTORY HERE
## setwd()

## Loading data
## load("dta.RData")

clustering_days_of_week_white = dta %>%
  filter(!is.na(close_day_of_week)) %>%
  filter(!is.na(white_third)) %>%
  mutate(n = 1,
         close_day_of_week = factor(close_day_of_week, levels = c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"))) %>%
  group_by(white_third, close_day_of_week) %>%
  summarise(n_requests_closed = sum(n, na.rm = TRUE)) %>%
  ggplot(aes(x = factor(close_day_of_week), y = n_requests_closed, fill = factor(white_third))) +
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_brewer(name = "% White Tercile", palette = "Blues", labels = c("Top", "Middle", "Bottom")) +
  labs(x = "Day of Week",
       y = "# of Requests Closed") +
  theme_classic()+
  theme(axis.text.x = element_text(angle = 45, hjust = 1),
        legend.position = "bottom",
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"))